/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgEntityInteractType
    {
        private readonly Dictionary<int, CfgEntityInteractType> _dataMap;
        private readonly List<CfgEntityInteractType> _dataList;


        public TbCfgEntityInteractType(ByteBuf _buf)
        {
            //first read common data
            _TbCommonEntityInteractType _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonEntityInteractType(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgEntityInteractType>(size * 3 / 2);
            _dataList = new List<CfgEntityInteractType>(size);

            for (int i = 0; i < size; i++)
            {
                CfgEntityInteractType _v;
                _v = CfgEntityInteractType.DeserializeCfgEntityInteractType(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgEntityInteractType> DataMap => _dataMap;
        public IReadOnlyList<CfgEntityInteractType> DataList => _dataList;

        public CfgEntityInteractType Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgEntityInteractType] config not found,id:" + key.ToString());

            return null;
        }

        public CfgEntityInteractType GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "entityinteracttype";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgEntityInteractType LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgEntityInteractType(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgEntityInteractType
    {
        private CfgEntityInteractType(ByteBuf _buf, _TbCommonEntityInteractType _commonData)
        {
            Id = _buf.ReadInt();
            Remark = _buf.ReadString();
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field0[dataIndex]; }
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            ActionID = _buf.ReadInt();
            Delay = _buf.ReadInt();
            IsHeroRotate = _buf.ReadBool();
            IsExtendRange = _buf.ReadBool();
            IsPlayHit = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; Weight = _commonData._field1[dataIndex]; }

            PostInit();
        }

        internal static CfgEntityInteractType DeserializeCfgEntityInteractType(ByteBuf _buf, _TbCommonEntityInteractType _commonData)
        {
            return new CfgEntityInteractType(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 策划备注 ---- 编辑器专用
        /// </summary>
        private string Remark { get; set; }
        /// <summary>
        /// 交互类型图标
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 交互类型名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 播放动作ID
        /// </summary>
        public int ActionID { get; private set; }
        /// <summary>
        /// 交互延时(毫秒)
        /// </summary>
        public int Delay { get; private set; }
        /// <summary>
        /// 是否转向实体
        /// </summary>
        public bool IsHeroRotate { get; private set; }
        /// <summary>
        /// 是否使用英雄触发距离
        /// </summary>
        public bool IsExtendRange { get; private set; }
        /// <summary>
        /// 是否播放受击表现(Hit动画和特效)
        /// </summary>
        public bool IsPlayHit { get; private set; }
        /// <summary>
        /// 交互类型权重
        /// </summary>
        public IntFloatKvList Weight { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonEntityInteractType
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IntFloatKvList> _field1 { get; private set; }
        internal _TbCommonEntityInteractType(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new IntFloatKvList[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ IntFloatKvList __v0; __v0 = new IntFloatKvList(_buf); __f0[__i0] = __v0;} }
        }

    }
}
